
<?php echo($javascript->link("countdown.js")); 
echo $javascript->link('prototype');
 ?>

<script>
function recallIndex(id)
{
	window.location ="/canastro/bidaki/sales/index/"+id;
}
</script>

<script>
	function highlightTime(row) {
		document.getElementById(row).style.backgroundColor = 'yellow';
	}
</script>

<?php  
$change_js = "recallIndex(this.value);";
echo __($form->input('category ',array('type'=>'select','options'=>$categories,'onchange' => $change_js,'empty'=> 'Select a Category' ))); 
?>


<div class="sales index" id="salesDiv">
<ul class="items">
<?php
$i = 0;
foreach ($sales as $sale):
?>
	
	<li>
		<table class="itemsTable">
			<tr>
				<td>
				
				<?php 	
							$photo = $sale['Item']['Photo'][0] ;
							echo $html->link($html->image('photos/home/'.$photo['urlPhoto'], array('width' => 100)),
											array('controller' => 'sales', 'action' => 'view', $sale['Sale']['id']),
											array('escape' => false));
							?>
							</td>
			</tr>
			<tr>
				<td><?php echo $html->link($sale['Item']['name'], array('controller' => 'items', 'action' => 'view', $sale['Item']['id'])); ?></td>
			</tr>
			<tr>
				<td id='<?php echo $i; ?>' class='countdown'>
				
					<?php 
						if($sale['Sale']['timeEnd'] <= date('Y-m-d H:i:s'))
						{	
							
							echo $sale['Sale']['timeEnd'].'<br>';
							echo __('Lasted: ').$timediff->timeDiff($sale['Sale']['originalTimeEnd'],$sale['Sale']['timeEnd']);  
							
						} else
						{
							$year = date("Y",strtotime($sale['Sale']['timeEnd'])); 
							$month = date("m",strtotime($sale['Sale']['timeEnd']));
							$day = date("d",strtotime($sale['Sale']['timeEnd']));
							$hour = date("H",strtotime($sale['Sale']['timeEnd']));
							$minutes = date("i",strtotime($sale['Sale']['timeEnd']));
							$seconds = date("s",strtotime($sale['Sale']['timeEnd']));	
							echo  '<script> countdown('.$year.','. $month.','. $day.','. $hour.','. $minutes.','. $seconds.','.$i.')</script>';
						}
						
					?>
				
				</td>
			</tr>
			<tr>
				<td>
				<?php
					echo number_format($sale['Sale']['currentPrice']*$currencyValue,2); 
					echo ' ';
					echo $currencyName;
				?>
				</td>
			</tr>
			<tr class="altrow">
				<td class = 'lastbidder'> <?php echo $sale['User']['login']; ?></td>
			</tr>
	
			<tr>
			
				<td class = "buttonspan clearfix">
					
					<?php if($sale['Sale']['timeEnd'] > date('Y-m-d H:i:s'))
							echo $html->link(__('Licitate', true), array('action' => 'licitate', $sale['Sale']['id'],'index',null), array('class'=>'buttonref', 'onclick'=>'highlightTime('.$i.')')); ?>

				</td>
			</tr>
			
			<tr>
			
				<td> 
					
				</td>
			</tr>
			
		</table>
	</li> 
	

<?php 		$i++;
		endforeach; ?>
</ul>
</div>
<div class="paging">
	<?php echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?>
 | 	<?php echo $paginator->numbers();?>
	<?php echo $paginator->next(__('next', true).' >>', array(), null, array('class' => 'disabled'));?>
</div>
